Skip to content

feat: 支持 OpenAI Responses API (/v1/responses) 渠道类型#91

Open
zhangzhenfei wants to merge 1 commit intoErlichLiu:mainfrom
zhangzhenfei:feat/openai-responses-api
Open

feat: 支持 OpenAI Responses API (/v1/responses) 渠道类型#91
zhangzhenfei wants to merge 1 commit intoErlichLiu:mainfrom
zhangzhenfei:feat/openai-responses-api

Conversation

@zhangzhenfei
Copy link
Copy Markdown

@zhangzhenfei zhangzhenfei commented Mar 9, 2026

Summary

  • 新增 openai-responses Provider 类型,支持 OpenAI Responses API (/v1/responses) 端点
  • 实现 ResponsesAdapter,处理 Responses API 特有的消息格式、SSE 事件解析、工具调用续接
  • 标题生成请求使用数组格式 input(非字符串),兼容各类中转站

变更文件

  • packages/core/src/providers/responses-adapter.ts — 新增 Responses API 适配器
  • packages/core/src/providers/index.ts — 注册 openai-responses 适配器
  • packages/shared/src/types/channel.ts — 新增 openai-responses Provider 类型
  • apps/electron/src/main/lib/channel-manager.ts — 支持 openai-responses 渠道连接测试
  • apps/electron/src/renderer/components/settings/ChannelForm.tsx — 渠道表单展示支持

Test plan

  • 创建 openai-responses 类型渠道,配置 API Key 和 Base URL
  • 发送聊天消息,验证流式输出正常
  • 验证对话标题自动生成正常
  • 验证工具调用(function calling)正常续接

🤖 Generated with Claude Code

新增 openai-responses Provider,接入 OpenAI 于 2025 年发布的新版
Responses API,与现有 Chat Completions 渠道并存、互不影响。

核心变更:
- 新增 ResponsesAdapter(packages/core):处理 /v1/responses 端点的
  请求构建与 SSE 解析,支持文本流、推理内容、工具调用三种事件类型
- 请求格式差异:input 替代 messages,instructions 替代 system role,
  工具定义采用扁平结构(无嵌套 function 对象)
- 工具续接:使用 function_call + function_call_output 输入项,
  通过 metadata.call_id 保留 call_id 供回传匹配
- shared 类型扩展:ProviderType 联合类型、默认 URL、显示名称
- channel-manager:三处 switch 新增 case 'openai-responses'
- ChannelForm UI:供应商选项与端点预览均已支持

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@JiwaniZakir JiwaniZakir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In channel-manager.ts, openai-responses is added as a fall-through to the existing openai test path (testChannel and testChannelDirect), but that test function almost probes the /chat/completions endpoint — not /responses. This means a valid openai-responses channel could fail its connectivity test, while a misconfigured one might pass if the base URL happens to serve Chat Completions. A dedicated test path (or at minimum passing the resolved endpoint URL into the shared test helper) would be more correct here.

In ChannelForm.tsx, PROVIDER_CHAT_PATHS['openai-responses'] is set to '/responses' (no /v1 prefix), which is consistent with how openai: '/chat/completions' works given that the default base URL already includes /v1. However, if a user sets a custom base URL that doesn't include /v1, they'll silently get the wrong path — worth a comment clarifying the assumption, or a validation note in the UI.

The new ResponsesAdapter type definitions look thorough — modeling ResponsesFunctionCallItem and ResponsesFunctionCallOutputItem as distinct input item types rather than overloading the role-based message structure is the right call for this API's format. It would be worth verifying that the id field on ResponsesFunctionCallItem (marked optional) is correctly round-tripped when the API returns it, since omitting it on continuation requests could cause the API to treat it as a new call rather than a resumption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants